function map_init(id, latlng,defAddress) {
    // 百度地图API功能
    defAddress?'':defAddress='贵阳市';
    var map = new BMap.Map(id);
    
    if(latlng){
        latlng = latlng.split(',');
        var point = new BMap.Point(latlng[1], latlng[0]);
        map.centerAndZoom(point, 12);
    }else{
        map.centerAndZoom(defAddress, 12);
        var center = map.getCenter();
        var point = new BMap.Point(center.lng, center.lat);
    }
    
    var marker = new BMap.Marker(point);// 创建标注   
    map.enableScrollWheelZoom();

    map.addOverlay(marker);             // 将标注添加到地图中
    marker.enableDragging();           // 可拖拽
    map.addEventListener('moveend', function (e) {
        center = map.getCenter();
        marker.setPosition(new BMap.Point(center.lng, center.lat));
        updatePoint(id,center.lng,center.lat);
    });
    marker.addEventListener('dragend', function (e) {
        updatePoint(id,e.point.lng,e.point.lat);
    });
    $('.'+id+'_search_bn').click(function () {
        var address = $('#'+id+'_search').val();

        var myGeo = new BMap.Geocoder();
        // 将地址解析结果显示在地图上,并调整地图视野
        myGeo.getPoint(address, function (point) {
            if (point) {
                map.centerAndZoom(point, 16);
            } else {
                alert("您选择地址没有解析到结果!");
            }
        }, defAddress);
    });
}

function updatePoint(id,lng,lat) {
    $('.'+id+'_lng').val(lng);
    $('.'+id+'_lat').val(lat);
}
